var app = getApp();
var config = require('../../config.js');
var util = require('../../js/common.util.js');
Page({
  data: {
    showView:false,
    passCount:0,
    submitCount:0,
    DataList:[],
    totalCount:0,
    businessStatus:0,
    page: 1,
    pageSize: 20,
    hasMoreData: true,
    imgPath: config.imgPath
  },
  onShareAppMessage: function () {

  },
  businessStatusTap(e){
    var type = e.target.dataset.type
    this.setData({
      page:1,
      businessStatus:type
    })
    this.loadData()
  },
  onShow: function () {
    this.setData({
      page:1
    })
    var name = wx.getStorageSync("username")
    if (name != null && name != '') {
      this.loadData()
    }
  },
  loadData(){
    let self = this
    app.request({
      url: 'api/wechat/GetPageOfBusinessByWechat',
      method: "GET",
      data: {
        page: self.data.page,
        pageSize: self.data.pageSize,
        businessStatus:self.data.businessStatus
      },
      success: function (res) {
        if(res != null){

          self.setData({
            totalCount: res.data.totalCount
          })
          if (res.data != null && res.data.Data.length > 0) {
            self.setData({
              showView: true
            })
            var listTemp = self.data.DataList

            if (self.data.page == 1) {
              listTemp = []
            }
            var list = res.data.Data
            for (var i = 0; i < list.length; i++) {
              list[i].createTime = util.formatTime(list[i].createTime)
            }
            if (list.length < self.data.pageSize) {
              self.setData({
                DataList: listTemp.concat(list),
                hasMoreData: false
              })
            } else {
              self.setData({
                DataList: listTemp.concat(list),
                hasMoreData: true,
                page: self.data.page + 1
              })
            }
          } else {
            self.setData({
              DataList: [],
              hasMoreData: false
            })
          }
        }
        }
    })
  },
  //下拉
  onPullDownRefresh: function () {
    this.setData({
      page: 1
    })
    this.loadData()
    wx.stopPullDownRefresh();
  },
  //上拉
  onReachBottom: function () {
    if (this.data.hasMoreData) {
      this.loadData()
    } else {
      wx.showToast({
        title: '没有更多了',
        icon: 'none',
      })
    }
  },
})